home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Developer / Include / ASM / xpk / xpkLibHeader.i < prev    next >
Encoding:
Text File  |  1997-05-11  |  5.3 KB  |  192 lines

  1.  
  2. **************** $VER: xpkLibHeader.i 1.3 (11.05.1997) ******************
  3.  
  4.     NOLIST
  5.     INCLUDE "exec/types.i"
  6.     INCLUDE "exec/initializers.i"
  7.     INCLUDE "exec/libraries.i"
  8.     INCLUDE "exec/lists.i"
  9.     INCLUDE "exec/alerts.i"
  10.     INCLUDE "exec/resident.i"
  11.     INCLUDE "dos/dos.i"
  12.     INCLUDE    "lvo.i"        ; contains all needed lvo's
  13.     LIST
  14.  
  15. **************************************************************************
  16.  
  17. ;    XDEF    InitTable
  18. ;    XDEF    Open
  19. ;    XDEF    Close
  20. ;    XDEF    Expunge
  21. ;    XDEF    Null
  22. ;    XDEF    LibName
  23.  
  24. **************************************************************************
  25.  
  26.     SECTION    "0", Code
  27. Start    MOVEQ    #-1,d0    ; return an error in case someone
  28.     RTS        ; tried to run as a program
  29.  
  30. ; A romtag structure.  Both "exec" and "ramlib" look for this structure to
  31. ; discover magic constants about you (such as where to start running you
  32. ; from...).
  33.  
  34. RomTag        DC.W    RTC_MATCHWORD    ; UWORD rt_MatchWord
  35.         DC.L    RomTag        ; APTR  rt_MatchTag
  36.         DC.L    EndCode        ; APTR  rt_EndSkip
  37.         DC.B    RTF_AUTOINIT    ; UBYTE rt_Flags
  38.         DC.B    VERSION        ; UBYTE rt_Version
  39.         DC.B    NT_LIBRARY    ; UBYTE rt_type
  40.         DC.B    0        ; BYTE  rt_Pri
  41.         DC.L    LibName        ; APTR  rt_Name
  42.         DC.L    IDString    ; APTR  rt_IDString
  43.         DC.L    InitTable    ; APTR  rt_Init  table for InitResident()
  44.  
  45. ; The romtag specified that we were "RTF_AUTOINIT". This means that the
  46. ; rt_Init structure member points to one of these tables below. If the
  47. ; AUTOINIT bit was not set then RT_INIT would point to a routine to run.
  48.  
  49. InitTable:
  50.     DC.L    LIB_SIZE        ; size of library base data space
  51.     DC.L    funcTable        ; pointer to function initializers
  52.     DC.L    dataTable        ; pointer to data initializers
  53.     DC.L    initRoutine        ; routine to run
  54.  
  55. funcTable:
  56. ;------ standard system routines
  57.     DC.L    Open
  58.     DC.L    Close
  59.     DC.L    Expunge
  60.     DC.L    Null
  61. ;------ the library definitions
  62.     DC.L    _XpksPackerInfo
  63.     DC.L    _XpksPackChunk
  64.     DC.L    _XpksPackFree
  65.     DC.L    _XpksPackReset
  66.     DC.L    _XpksUnpackChunk
  67.     DC.L    _XpksUnpackFree
  68. ;------ function table end marker
  69.     DC.L    -1
  70.  
  71. ; The data table initializes static data structures. The format is specified
  72. ; in exec/InitStruct routine's manual pages. The INITBYTE/INITWORD/INITLONG
  73. ; routines are in the file "exec/initializers.i". The first argument is the
  74. ; offset from the library base for this byte/word/long. The second argument
  75. ; is the value to put in that cell. The table is null terminated.
  76.  
  77. dataTable:
  78.     INITBYTE    LN_TYPE,NT_LIBRARY
  79.     INITLONG    LN_NAME,LibName
  80.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  81.     INITWORD    LIB_VERSION,VERSION
  82.     INITWORD    LIB_REVISION,REVISION
  83.     INITLONG    LIB_IDSTRING,IDString
  84.     DC.L        0
  85.  
  86. ; This routine gets called after the library has been allocated. The library
  87. ; pointer is in D0. The segment list is in A0. If it returns non-zero then
  88. ; the library will be linked into the library list.
  89.  
  90. SegList        DC.L    0
  91. initRoutine:
  92. ;------ get the library pointer into a convenient A register
  93.     MOVE.L    A5,-(A7)
  94.     MOVEA.L    D0,A5
  95. ;------ save a pointer to our loaded code
  96.     MOVE.L    A0,SegList
  97. ;
  98. ; specific openings here
  99. ;
  100.     JSR    _InitCode
  101.     TST.L    D0
  102.     BNE.B    .kill
  103.     MOVE.L    A5,D0
  104. .end    MOVEA.L    (A7)+,A5
  105.     RTS
  106. .kill    JSR    _ExitCode
  107.     MOVEQ    #0,D0
  108.     BRA.B    .end
  109.  
  110. ; here begins the system interface commands. When the user calls
  111. ; OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  112. ; into a call to the following routines (Open/Close/Expunge). Exec has
  113. ; already put our library pointer in A6 for us. Exec has turned off task
  114. ; switching while in these routines (via Forbid/Permit), so we should not
  115. ; take too long in them.
  116.  
  117. ; Open returns the library pointer in D0 if the open was successful. If the
  118. ; open failed then null is returned. It might fail if we allocated memory
  119. ; on each open, or if only one application could have the library open at
  120. ; a time...
  121.  
  122. Open:        ; (libptr:A6, version:D0)
  123. ;------ mark us as having another opener
  124.     ADDQ.W    #1,LIB_OPENCNT(A6)
  125.     BCLR    #LIBB_DELEXP,LIB_FLAGS(A6)
  126.     MOVE.L    A6,D0
  127.     RTS
  128.  
  129. ; There are two different things that might be returned from the Close
  130. ; routine. If the library is no longer open and there is a delayed expunge
  131. ; then Close should return the segment list (as given to Init). Otherwise
  132. ; close should return NULL.
  133.  
  134. Close:        ; (libptr:A6)
  135. ;------ set the return value
  136.     MOVEQ    #0,D0
  137. ;------ mark us as having one fewer openers
  138.     SUBQ.W   #1,LIB_OPENCNT(A6)
  139. ;------ see if there is anyone left with us open
  140.     BNE.B    OneLeft
  141. ;------ do the expunge
  142.     BTST    #LIBB_DELEXP,LIB_FLAGS(a6)
  143.     BEQ.B    DelExp
  144.     BSR.B    Expunge
  145. OneLeft
  146. DelExp    RTS
  147.  
  148. ; There are two different things that might be returned from the Expunge
  149. ; routine. If the library is no longer open then Expunge should return the
  150. ; segment list (as given to Init). Otherwise Expunge should set the delayed
  151. ; expunge flag and return NULL.
  152. ; One other important note: because Expunge is called from the memory
  153. ; allocator, it may NEVER Wait() or otherwise take long time to complete.
  154.  
  155. Expunge:    ; (libptr: A6)
  156.     MOVEM.L    D2/A5/A6,-(A7)
  157.     MOVEA.L    A6,A5
  158.     MOVEA.L    4.W,A6
  159. ;------ see if anyone has us open
  160.     TST.W    LIB_OPENCNT(A5)
  161.     BEQ.B    DoIt
  162.     BSET    #LIBB_DELEXP,LIB_FLAGS(A5)
  163.     MOVEQ    #0,D0
  164.     BRA.B    Expunge_End
  165. DoIt
  166. ;------ go ahead and get rid of us.  Store our seglist in D2
  167.     MOVE.L    SegList(PC),D2
  168. ;------ unlink from library list
  169.     MOVEA.L    A5,A1
  170.     JSR    _LVORemove(A6)
  171. ;
  172. ; device specific closings here...
  173.     JSR    _ExitCode
  174. ;
  175. ;------ free our memory
  176.     MOVEQ    #0,D0
  177.     MOVEA.L    A5,A1
  178.     MOVE.W    LIB_NEGSIZE(A5),D0
  179.     SUBA.L    D0,A1
  180.     ADD.W    LIB_POSSIZE(A5),D0
  181.     MOVEA.L    4.W,A6
  182.     JSR    _LVOFreeMem(A6)
  183. ;------ set up our return value
  184.     MOVE.L    D2,D0
  185.  
  186. Expunge_End:
  187.     MOVEM.L    (A7)+,D2/A5/A6
  188.     RTS
  189.  
  190. Null:    MOVEQ    #0,D0
  191. EndCode    RTS
  192.